//Linux C plus plus file
/************************************************************************
*
*
*       			FileName:thread.cpp
*
*         			Author.wzj
*
*       			Email:345517039@qq.com
*
*      	    		Create:2017-06-22 23:44:03
*
*      		    	Description:-
*
*
*************************************************************************/
#include "thread.h"


/**
 * @brief 
 */
thread::thread(){

}


/**
 * @brief 
 */
thread::~thread(){

}



/**
 * @brief 
 *
 * @param stacksize
 *
 * @return 
 */
int thread::setPthreadAttr(size_t stacksize){
	int ret = -1;
	ret = pthread_attr_setstack(&this->ctx.attr,NULL,stacksize);
	if(ret == 0){
		return  1;
	}
	return -1;
}


/**
 * @brief 
 *
 * @param priority
 *
 * @return 
 */
int thread::setPthreadPriority(int priority){
	this->ctx.param.sched_priority = priority;
	int ret = pthread_attr_setschedparam(&this->ctx.attr,&this->ctx.param);
	if(ret == 0){
		return  1;
	}
	return -1;
}


/**
 * @brief 
 *
 * @param policy
 *
 * @return 
 */
int thread::setPthreadSchedulePolicy(int policy){
	int ret = 0;
	ret = pthread_attr_setschedpolicy(&this->ctx.attr, policy);
	if(ret == 0){
		return 1;
	}
	return -1;
}


/**
 * @brief 
 *
 * @param no
 *
 * @return 
 */
int thread::setPthreadBindCpuNo(int no){
	int ret = 0;
	CPU_ZERO(&this->ctx.mask);
	CPU_SET(no, &this->ctx.mask);
	ret = pthread_setaffinity_np(this->ctx.id,sizeof(this->ctx.mask), &this->ctx.mask);
	if(ret == 0){
		return  1;
	}
	return -1;
}








